<?php
namespace app\mouth\controller;
use app\mouth\common\Api;
use app\mouth\model\CircleModel;
use think\Db;

/**
 * 圈子--发现控制器
 * Class CircleApi
 * @package app\mouth\controller
 */
class CircleApi extends Api{
    public function index(){
        $index =CircleModel::index();
        return $this->jsons('40006','获取成功',$index);
    }
    /**
     * 加入圈子
     */
    public function joinTheCircle(){
        $index = (new CircleModel)->joinTheCircle((int)input('c_id'),$this->quanzi_id['id'],1);
        $this->add($index);
    }
    /**
     * 退出圈子
     */
    public function quitTheCircle(){
        $index = (new CircleModel)->joinTheCircle((int)input('c_id'),$this->quanzi_id['id'],2);
        $this->add($index);
    }

    /**
     * 圈子搜索
     * name  名称
     */
    public function circleSearch(){
        $Search = CircleModel::Search(input('name'));
        return $this->jsons('40006','获取成功',$Search);
    }

    /**
     * 圈子详细
     * id  圈子id
     * 需要田哥给index 里面的参数
     */
    public function circleDetails(){
        $circlewhole = CircleModel::circleDetails((int)input('id'),$this->quanzi_id['id']);
        return $this->jsons('40006','获取成功',$circlewhole);
    }

    /**
     * 关注
     */
    public function circleAttention(){
        $id['u_id']=input('u_id');
        $id['c_id']=input('c_id');
        $Attention = CircleModel::Attention($id);
        if ($Attention){
            return $this->jsons('40006','关注成功',[]);
        }
        return $this->jsons('40003','关注失败',[]);
    }
    /**
     * 取消关注
     */
    public function canceAttention(){
        $u_id=input('u_id');
        $c_id=input('c_id');
        $Attention = CircleModel::canceAttention($u_id,$c_id);
        if ($Attention){
            return $this->jsons('40006','取消成功',[]);
        }
        return $this->jsons('40003','取消失败',[]);
    }

    /**
     * 添加帖子
     */
    public function addPost(){
        $Deposit['uid'] = $this->quanzi_id['id'];
        $Deposit['nickname']=$this->nickname;
        $Deposit['portrait']=$this->portrait;
        $Attention = (new CircleModel)->joinThePost(input(),$Deposit);
        if ($Attention === true){
            return $this->jsons('40006','添加成功',[]);
        }
        return $this->jsons('40003','添加失败',$Attention);
    }
}